Skip to content

Make parameter length based on underlying column length except for complex ops#2627

Open
simonsabin wants to merge 5 commits intoAzure:mainfrom
simonsabin:paramlength
Open

Make parameter length based on underlying column length except for complex ops#2627
simonsabin wants to merge 5 commits intoAzure:mainfrom
simonsabin:paramlength

Conversation

@simonsabin
Copy link
Collaborator

@simonsabin simonsabin commented Mar 20, 2025

Why make this change?

Closes #2626

What is this change?

Where a parameter is linked to an underlying column in the data model the length is stored
When the query is executed the length is used to ensure parameters have consistent lengths

For certain operations the value is padded with escape characters or %s, these need to be allowed for. In those cases the length is set to -1 (max) in order that the extra characters are allowed for AND consistent lengths are maintained

How was this tested?

  • Integration Tests

Checking the resultant query is using the right length was done using trace. Not sure with the architecture whether it would be possible to mock at that level.

Sample Request(s)

See new tests TestFilterParamForStringFilterWorkWithComplexOp and TestFilterParamForStringFilterWorkWithNotContains

Copy link
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you for raising and then solving this issue. Just had a few nits, and a question.

@simonsabin
Copy link
Collaborator Author

simonsabin commented Mar 20, 2025 via email

@simonsabin
Copy link
Collaborator Author

applied suggested changes

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle
Copy link
Contributor

Pipeline failures are just whitespace format.

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@Aniruddh25
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle aaronburtle modified the milestones: Backlog, March 2026 Mar 6, 2026
@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@simon-sabin-BE
Copy link

thanks for perservering with this

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle aaronburtle force-pushed the paramlength branch 2 times, most recently from 3189c7e to bf4b8e9 Compare March 12, 2026 02:21
…ations

- Add Length property to DbConnectionParam and ColumnDefinition
- Add GetLengthForParam to SourceDefinition for parameter length lookup
- Pass lengthOverride flag through filter parsing chain for contains/startsWith/endsWith
- Set SqlParameter.Size for VarChar/NVarChar/Char/NChar types in MsSqlQueryExecutor
- Prevents implicit varchar(max) truncation when using LIKE with parameterized queries
- Update ColumnDefinition field count assertion in serialization tests
@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Session context parameters (used by sp_set_session_context) are string
values that get SqlDbType.NVarChar inferred by default. Previously, the
Size was set to -1 (varchar(max)) for all NVarChar parameters when no
explicit Length was configured, causing sp_set_session_context to fail
with 'An invalid parameter or option was specified'.

Now Size is only set when DbConnectionParam.Length is explicitly non-null,
which occurs only for query parameters where column metadata provides a
length or when lengthOverride is set for LIKE operations.
@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Read ColumnSize from the schema DataTable during column introspection
so that SqlParameter.Size is set to match the actual column length for
string types (varchar, nvarchar, char, nchar). This completes the
parameter length feature by wiring up the metadata source.
@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Populating Length from ColumnSize caused parameter.Size to be set for
ALL string parameters (eq/neq), not just LIKE operations. This caused
SQL Server to truncate parameter values to column length, breaking
equality filters where the parameter value exceeds the column size.
@aaronburtle
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @simonsabin and sorry this was so delayed.

@anushakolan anushakolan self-assigned this Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 cri Customer Reported issue

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

For MSSQL Parameters are created with length based on their value not the underlying model length this causes plan reuse issues

7 participants